"""Setup the eshop application"""
import logging

from paste.deploy import appconfig
from pylons import config
from elixir import *
from model import *

from eshop.config.environment import load_environment

log = logging.getLogger(__name__)

def setup_config(command, filename, section, vars):
    """Place any commands to setup eshop here"""
    conf = appconfig('config:' + filename)
    print "loading environment"
    load_environment(conf.global_conf, conf.local_conf)
#    print "Creating tables"
#    model.metadata.create_all(bind=config['pylons.g'].sa_engine)
#    print "Successfully setup"
    metadata.drop_all(checkfirst=False)
    metadata.create_all()
    
    group_vp = Group(name='VP')
    role_admin = Role(name='admin')
    role_user = Role(name='user')
 
    user_admin = User(username='admin', password=u'admin', email='admin@eshop.ua', group=group_vp)
    user_admin.roles.append(role_admin)
    
    objectstore.flush()
    print "done populating data..."  
